<?php if(!defined('HDPHP_PATH'))EXIT;
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."access`");
$db->exe("CREATE TABLE `".$db_prefix."access` (
  `aid` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`aid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='权限分配表'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."attribute`");
$db->exe("CREATE TABLE `".$db_prefix."attribute` (
  `attr_id` smallint(6) unsigned NOT NULL AUTO_INCREMENT,
  `attr_name` varchar(45) DEFAULT NULL COMMENT '属性名称',
  `attr_type` tinyint(4) unsigned DEFAULT NULL COMMENT '属性类型 0 普通属性 1 规格属性',
  `attr_value` varchar(255) DEFAULT NULL COMMENT '属性值',
  `attr_input_type` tinyint(4) DEFAULT NULL COMMENT '录入方式',
  `cat_id` int(11) unsigned NOT NULL COMMENT '商品类型',
  PRIMARY KEY (`attr_id`),
  KEY `fk_attribute_goods_type_idx` (`cat_id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='类型属性表'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."brand`");
$db->exe("CREATE TABLE `".$db_prefix."brand` (
  `brand_id` int(11) NOT NULL AUTO_INCREMENT,
  `brand_name` char(45) DEFAULT NULL COMMENT '品牌名称',
  `brand_logo` varchar(255) DEFAULT NULL COMMENT '品牌logo',
  `brand_order` smallint(6) DEFAULT '100',
  PRIMARY KEY (`brand_id`)
) ENGINE=MyISAM AUTO_INCREMENT=15 DEFAULT CHARSET=utf8 COMMENT='品牌表'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."category`");
$db->exe("CREATE TABLE `".$db_prefix."category` (
  `cid` smallint(5) unsigned NOT NULL AUTO_INCREMENT,
  `cat_name` varchar(45) DEFAULT NULL COMMENT '栏目名称',
  `pid` smallint(6) DEFAULT NULL COMMENT '父级id',
  `is_show` tinyint(4) DEFAULT NULL COMMENT '是否显示',
  `cat_key` varchar(80) DEFAULT NULL COMMENT '栏目关键字',
  `cat_desc` varchar(255) DEFAULT NULL COMMENT '栏目描述',
  `measure_unit` char(10) DEFAULT NULL COMMENT '数量单位',
  `grade` tinyint(4) DEFAULT NULL COMMENT '价格区间',
  `cat_id` int(11) NOT NULL COMMENT '类型id',
  PRIMARY KEY (`cid`)
) ENGINE=MyISAM AUTO_INCREMENT=221 DEFAULT CHARSET=utf8 COMMENT='栏目表'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."config`");
$db->exe("CREATE TABLE `".$db_prefix."config` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '配置主键',
  `title` varchar(45) DEFAULT NULL COMMENT '配置显示中文名',
  `name` varchar(45) DEFAULT NULL COMMENT '配置名称',
  `value` varchar(255) DEFAULT NULL COMMENT '配置值',
  `type` enum('text','radio','textarea') DEFAULT NULL COMMENT '显示类型:text/radio/textarea',
  `info` varchar(255) DEFAULT NULL COMMENT '参数如：radio   1|开启,0|关闭',
  `isshow` smallint(6) DEFAULT '1' COMMENT '是否显示 1显示 0 不显示 默认显示',
  `orderlist` smallint(6) DEFAULT '100' COMMENT '显示时的排序 默认100',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COMMENT='配置表'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."goods`");
$db->exe("CREATE TABLE `".$db_prefix."goods` (
  `gid` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT '主键',
  `goods_name` char(100) DEFAULT NULL COMMENT '商品名称',
  `goods_sn` varchar(50) DEFAULT NULL COMMENT '货号',
  `goods_weight` varchar(45) DEFAULT NULL COMMENT '重量',
  `weight_unit` varchar(45) DEFAULT NULL COMMENT '重量单位',
  `original_img` varchar(255) DEFAULT NULL COMMENT '首页原图',
  `goods_img` varchar(255) DEFAULT NULL COMMENT '商品图片',
  `goods_thumb` varchar(255) DEFAULT NULL COMMENT '商品缩略图',
  `sale_time` int(11) DEFAULT NULL COMMENT '上架时间',
  `goods_number` mediumint(9) DEFAULT NULL COMMENT '库存数量',
  `goods_click` mediumint(9) DEFAULT NULL COMMENT '查看次数',
  `uid` int(11) DEFAULT NULL COMMENT '管理员',
  `is_hot` tinyint(4) unsigned DEFAULT '0' COMMENT '热销',
  `is_new` tinyint(4) unsigned DEFAULT '0' COMMENT '新品',
  `is_best` tinyint(4) unsigned DEFAULT '0' COMMENT '精品',
  `market_price` decimal(10,2) DEFAULT NULL COMMENT '市场价',
  `goods_price` decimal(10,2) DEFAULT NULL COMMENT '商城价',
  `is_on_sale` tinyint(4) DEFAULT NULL COMMENT '是否上架',
  `recycle` tinyint(4) unsigned NOT NULL DEFAULT '0' COMMENT '是否放入回收站 为1时放入回收站',
  `brand_id` int(11) NOT NULL COMMENT '品牌',
  `category_cid` smallint(6) NOT NULL COMMENT '栏目',
  `goods_type` int(11) NOT NULL COMMENT '商品类型',
  PRIMARY KEY (`gid`),
  KEY `fk_goods_brand1_idx` (`brand_id`),
  KEY `fk_goods_category1_idx` (`category_cid`),
  KEY `fk_goods_goods_type1_idx` (`goods_type`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='商品表'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."goods_attr`");
$db->exe("CREATE TABLE `".$db_prefix."goods_attr` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `attr_value` varchar(255) DEFAULT NULL COMMENT '属性值',
  `attr_price` decimal(10,2) DEFAULT NULL COMMENT '附加价格',
  `goods_gid` int(11) NOT NULL COMMENT '商品主键',
  `attr_id` smallint(6) NOT NULL COMMENT '属性ID',
  PRIMARY KEY (`id`),
  KEY `fk_goods_attr_goods1_idx` (`goods_gid`),
  KEY `fk_goods_attr_attribute1_idx` (`attr_id`)
) ENGINE=MyISAM AUTO_INCREMENT=53 DEFAULT CHARSET=utf8 COMMENT='商品属性'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."goods_data`");
$db->exe("CREATE TABLE `".$db_prefix."goods_data` (
  `gd_id` int(11) NOT NULL AUTO_INCREMENT,
  `goods_key` varchar(100) DEFAULT NULL COMMENT '关键字',
  `goods_desc` varchar(200) DEFAULT NULL COMMENT '商品描述',
  `goods_body` text COMMENT '商品详情',
  `goods_gid` int(11) NOT NULL,
  PRIMARY KEY (`gd_id`),
  KEY `fk_goods_data_goods1_idx` (`goods_gid`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='商品信息（商品副表）'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."goods_gallery`");
$db->exe("CREATE TABLE `".$db_prefix."goods_gallery` (
  `goods_gallery_id` int(11) NOT NULL AUTO_INCREMENT,
  `img_url` varchar(255) DEFAULT NULL COMMENT '中图',
  `thumb_url` varchar(255) DEFAULT NULL COMMENT '缩略图',
  `img_original` varchar(255) DEFAULT NULL COMMENT '原图',
  `goods_gid` int(11) NOT NULL,
  PRIMARY KEY (`goods_gallery_id`),
  KEY `fk_goods_gallery_goods1_idx` (`goods_gid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='商品图片'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."goods_type`");
$db->exe("CREATE TABLE `".$db_prefix."goods_type` (
  `cat_id` int(11) NOT NULL AUTO_INCREMENT,
  `cat_name` varchar(45) CHARACTER SET utf8 NOT NULL COMMENT '类型名称',
  PRIMARY KEY (`cat_id`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=latin1 COMMENT='商品类型'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."node`");
$db->exe("CREATE TABLE `".$db_prefix."node` (
  `nid` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`nid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='节点表'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."order`");
$db->exe("CREATE TABLE `".$db_prefix."order` (
  `oid` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单主键',
  `order_sn` int(11) DEFAULT NULL COMMENT '订单号',
  `consignee` varchar(45) DEFAULT NULL COMMENT '收货人',
  `address` varchar(200) DEFAULT NULL COMMENT '收货地址',
  `amount` decimal(10,2) DEFAULT NULL COMMENT '价格统计（总价格）',
  `order_status` tinyint(4) DEFAULT NULL COMMENT '订单状态',
  `addtime` int(11) DEFAULT NULL COMMENT '生成时间',
  `mobile` varchar(45) DEFAULT NULL COMMENT '手机',
  `tel` varchar(45) DEFAULT NULL COMMENT '电话',
  `zipcode` smallint(6) DEFAULT NULL COMMENT '邮编',
  `order_note` varchar(255) DEFAULT NULL COMMENT '备注',
  `goods_gid` int(11) NOT NULL,
  `user_id` int(11) DEFAULT NULL COMMENT '用户id',
  PRIMARY KEY (`oid`),
  KEY `fk_order_goods1_idx` (`goods_gid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='订单表'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."order_goods`");
$db->exe("CREATE TABLE `".$db_prefix."order_goods` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '订单列表主键',
  `order_goodscol` varchar(45) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='订单列表'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."product`");
$db->exe("CREATE TABLE `".$db_prefix."product` (
  `product_id` int(11) NOT NULL AUTO_INCREMENT COMMENT '货品主键',
  `product_sn` smallint(6) DEFAULT NULL COMMENT '货号',
  `product_number` int(11) DEFAULT NULL COMMENT '货品库存数量',
  `goods_attr_id` varchar(45) NOT NULL,
  `goods_gid` int(11) NOT NULL,
  PRIMARY KEY (`product_id`),
  KEY `fk_product_goods_attr1_idx` (`goods_attr_id`),
  KEY `fk_product_goods1_idx` (`goods_gid`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='货品表'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."role`");
$db->exe("CREATE TABLE `".$db_prefix."role` (
  `rid` tinyint(4) NOT NULL AUTO_INCREMENT COMMENT '角色主键',
  `role_name` varchar(45) DEFAULT NULL COMMENT '角色名称',
  PRIMARY KEY (`rid`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='角色表'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."user`");
$db->exe("CREATE TABLE `".$db_prefix."user` (
  `uid` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(45) DEFAULT NULL COMMENT '用户名',
  `password` varchar(32) DEFAULT NULL COMMENT '密码',
  `token` varchar(32) DEFAULT NULL COMMENT '令牌',
  `rid` tinyint(4) NOT NULL COMMENT '角色id',
  PRIMARY KEY (`uid`),
  KEY `fk_user_role1_idx` (`rid`)
) ENGINE=MyISAM AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COMMENT='用户表'");
$db->exe("DROP TABLE IF EXISTS `".$db_prefix."user_role`");
$db->exe("CREATE TABLE `".$db_prefix."user_role` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='角色用户关联表'");
